package cn.kgc.springmvcday02.controller;

import cn.kgc.springmvcday02.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author 课工场
 * @date 2023/10/14
 * @description  学生业务的控制层
 * @RequestMapping  解析
 * 注解属性 "path"  String[]   多路径匹配
 *  method   RequestMethod[]    设置  RequestMapping  能处理的请求方式
 *          RequestMethod.POST   RequestMethod.GET
 *
 * @PostMapping   标识请求方式是post
 *
 *
 */
@Controller
@RequestMapping("student")
public class StudentController {


    @RequestMapping(path = {"add","insert"},method ={RequestMethod.POST,RequestMethod.GET} )
//    @PostMapping("add")
    // 添加学生信息    /student/add
    public ModelAndView  addStudent(){
        // 视图和模型对象      视图名  +  数据
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("main");

        Student student = new Student();
        student.setName("tom");
        student.setAge(20);

        modelAndView.addObject("student",student);

        return modelAndView;   // 转发
    }

    // 删除学生信息   /student/delete
    @RequestMapping(value = "delete",method = RequestMethod.DELETE)
    public ModelAndView  deleteStudent(){
        // 视图和模型对象      视图名  +  数据
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("main");
        modelAndView.addObject("info","删除成功");
        return modelAndView;
    }


}
